package com.oracle.intelagr.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oracle.intelagr.common.PageModel;
import com.oracle.intelagr.entity.BAirmonitoring;
import com.oracle.intelagr.entity.BSoilmonitoring;
import com.oracle.intelagr.entity.BSoilmonitoringExample;
import com.oracle.intelagr.entity.BSoilmonitoringExample.Criteria;
import com.oracle.intelagr.mapper.BSoilmonitoringMapper;
import com.oracle.intelagr.service.ISoilmoniService;

@Service
public class SolimoniServiceImpl implements ISoilmoniService{
	@Autowired
	private BSoilmonitoringMapper bSoilmonitoringMapper;
	
	public void query(PageModel pageModel, Map map) {
		BSoilmonitoringExample example = new BSoilmonitoringExample();
		Criteria cri = example.createCriteria();
		if(map.get("startMoniorDate")!=null) {
			cri.andMonitordateGreaterThanOrEqualTo((Date)map.get("startMoniorDate"));
		}
		if(map.get("endMoniorDate")!=null) {
			cri.andMonitordateLessThanOrEqualTo((Date)map.get("endMoniorDate"));
		}
		cri.andDeleteflagEqualTo("N");
		PageHelper.startPage(pageModel.getPage(), pageModel.getPageSize());
		List<BSoilmonitoring> selectByExample = bSoilmonitoringMapper.selectByExample(example);
		PageInfo pageInfo = new PageInfo(selectByExample);
		pageModel.setResult(selectByExample);
		pageModel.setTotalCount((int)pageInfo.getTotal());
	}

	public void save(BSoilmonitoring soilmoni) {
		bSoilmonitoringMapper.insert(soilmoni);
	}

	public void update(BSoilmonitoring soilmoni) {
		bSoilmonitoringMapper.updateByPrimaryKeySelective(soilmoni);
	}

	public BSoilmonitoring queryById(Integer id) {
		return bSoilmonitoringMapper.selectByPrimaryKey(id);
	}

	public void delete(int[] ids) {
		if(ids!=null) {
			for(int id:ids) { 
				BSoilmonitoring bSoilmonitoring = new BSoilmonitoring();
				bSoilmonitoring.setId(id);
				bSoilmonitoring.setDeleteflag("Y");
				bSoilmonitoringMapper.updateByPrimaryKeySelective(bSoilmonitoring);
			}
		}
	}

}
